<template>
  <view class="layout">
		<view class="navbar">
			<view class="statusBar" :style="{height:getStatusBarHeight()+'px'}"></view>
			<view class="titleBar" :style="{height:getTitleBarHeight()+'px',marginLeft:getLeftIconLeft()+'px'}">
				<view class="title">{{title}}</view>
				<view class="search" @click="goSearch">
					<uni-icons class="icon" type="search" color="#888" size="18"></uni-icons>
					<view class="text">搜索</view>
				</view>
			</view>
		</view>
		
		<!-- fixed定位的元素脱离标准文档流，这里需要加个占位盒子，使得swiper不被fixed元素覆盖 -->
		<view class="fill" :style="{height:getNavBarHeight()+'px'}">
			
		</view>
  </view>
</template>

<script setup>
// import {computed, ref} from 'vue'
// const SYSTEM_INFO = uni.getSystemInfoSync()
// // console.log(SYSTEM_INFO)
// const statusBarHeight = ref(SYSTEM_INFO.statusBarHeight)
// // const MENU_BUTTON = uni.getMenuButtonBoundingClientRect()
// // 注：top是胶囊顶上边到最顶头的距离，bottom是胶囊底边到最顶头的距离
// // 可以通过top值减去statusBarHeight得到胶囊离状态栏的距离
// // console.log(MENU_BUTTON)
// const { top, height } = uni.getMenuButtonBoundingClientRect()
// // console.log(top, height)
// // 胶囊高加上上下边距得到胶囊总体高度
// const titleBarHeight = computed(() => height + (top - statusBarHeight.value) * 2)
// console.log(titleBarHeight.value)

// 经抽离后的代码
import {computed, ref} from 'vue'
import { getStatusBarHeight, getTitleBarHeight, getNavBarHeight, getLeftIconLeft } from '@/utils/system.js'

defineProps({
	title: {
		type: String,
		default: '壁纸'
	}
})

const goSearch = () => {
	uni.navigateTo({
		url: '/pages/search/search'
	})
}
</script>

<style lang="scss" scoped>
.layout {
	.navbar {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		background:
		linear-gradient(to bottom, transparent, #fff 400rpx),
		linear-gradient(to right, #beecd8 20%, #F4E2D8);
		z-index: 999;
		.statusBar {
			// border: 1px solid red;
		}
		.titleBar {
			display: flex;
			align-items: center;
			padding: 0 30rpx;
			height: 100rpx;
			// border: 1px solid #000;
			.title {
				font-size: 44rpx;
				font-weight: 700;
				color: $text-font-color-1;
			}
			.search {
				display: flex;
				align-items: center;
				margin-left: 30rpx;
				width: 200rpx;
				height: 50rpx;
				font-size: 28rpx;
				color: #999;
				border: 1px solid #fff;
				border-radius: 60rpx;
				background: rgba(255,255,255,.4);
				.icon {
					margin-left: 5rpx;
				}
				.text {
					padding-left: 10rpx;
				}
			}
		}
	}
}
</style>